package btanalyzer.db.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;

@Entity
@Table(name="DIGGED_SITE", uniqueConstraints={
		@UniqueConstraint(columnNames={"URL", "DIGG_TASK_ID"}, name="DIGGED_SITE__URL__DIGG_TASK_ID_UK")
})
public class DiggedSite {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
    @SequenceGenerator(name = "seq", sequenceName = "DIGGED_SITE_SEQ")
    @Column(name="DIGGED_SITE_ID")
	private Long id;
	public void setId(Long id) {
		this.id = id;
	}
	public Long getId() {
		return id;
	}
	
	@NotNull
	@Column(name="URL")
	private String url;
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUrl() {
		return url;
	}
	
	@NotNull
	@Column(name="FILE_PATH")
	private String filePath;
	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}
	public String getFilePath() {
		return filePath;
	}
	
//	@NotNull
	@Column(name="DOWNLOADED_DATE")
	private Date downloadedDate;
	public void setDownloadedDate(Date downloadedDate) {
		this.downloadedDate = downloadedDate;
	}
	public Date getDownloadedDate() {
		return downloadedDate;
	}
	
	@NotNull
	@ManyToOne
	@JoinColumn(name="DIGG_TASK_ID")
	private DiggTask diggTask;
	public void setDiggTask(DiggTask diggTask) {
		this.diggTask = diggTask;
	}
	public DiggTask getDiggTask() {
		return diggTask;
	}
	
	@NotNull
	@ManyToOne
	@JoinColumn(name="CATEGORY_ID")
	private Category category;
	public void setCategory(Category category) {
		this.category = category;
	}
	public Category getCategory() {
		return category;
	}
	
	@OneToMany(mappedBy="diggedSite", cascade=CascadeType.ALL)
	private Set<Torrent> torrents = new HashSet<Torrent>();
	public void setTorrents(Set<Torrent> torrents) {
		this.torrents = torrents;
	}
	public Set<Torrent> getTorrents() {
		return torrents;
	}
	
}
